home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Microsoft Plateform / Visual Basic 5.0 / Msvb50.ace / msvb50 / MSVB50 / VB / SETUPKIT / SETUP1 / SERVERDT.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-11-14  |  16.4 KB  |  432 lines

  1. VERSION 5.00
  2. Begin VB.Form frmRemoteServerDetails 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "#"
  5.    ClientHeight    =   4545
  6.    ClientLeft      =   3195
  7.    ClientTop       =   2400
  8.    ClientWidth     =   7800
  9.    ControlBox      =   0   'False
  10.    Icon            =   "serverdt.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4545
  15.    ScaleWidth      =   7800
  16.    Begin VB.CommandButton cmdCancel 
  17.       Caption         =   "#"
  18.       Height          =   375
  19.       Left            =   5580
  20.       MaskColor       =   &H00000000&
  21.       TabIndex        =   5
  22.       Top             =   3930
  23.       Width           =   1935
  24.    End
  25.    Begin VB.CommandButton cmdOK 
  26.       Caption         =   "#"
  27.       Default         =   -1  'True
  28.       Enabled         =   0   'False
  29.       Height          =   375
  30.       Left            =   3540
  31.       MaskColor       =   &H00000000&
  32.       TabIndex        =   4
  33.       Top             =   3930
  34.       Width           =   1935
  35.    End
  36.    Begin VB.ComboBox cboNetworkProtocol 
  37.       Height          =   300
  38.       Left            =   2400
  39.       Style           =   2  'Dropdown List
  40.       TabIndex        =   3
  41.       Top             =   3165
  42.       Width           =   5100
  43.    End
  44.    Begin VB.TextBox txtNetworkAddress 
  45.       Height          =   300
  46.       Left            =   2400
  47.       TabIndex        =   1
  48.       Top             =   2535
  49.       Width           =   5100
  50.    End
  51.    Begin VB.Frame Frame1 
  52.       Height          =   555
  53.       Left            =   225
  54.       TabIndex        =   7
  55.       Top             =   1395
  56.       Width           =   7290
  57.       Begin VB.Label lblServerName 
  58.          Alignment       =   2  'Center
  59.          AutoSize        =   -1  'True
  60.          Caption         =   "#"
  61.          BeginProperty Font 
  62.             Name            =   "MS Sans Serif"
  63.             Size            =   8.25
  64.             Charset         =   0
  65.             Weight          =   700
  66.             Underline       =   0   'False
  67.             Italic          =   0   'False
  68.             Strikethrough   =   0   'False
  69.          EndProperty
  70.          Height          =   195
  71.          Left            =   135
  72.          TabIndex        =   8
  73.          Top             =   240
  74.          Width           =   7020
  75.          WordWrap        =   -1  'True
  76.       End
  77.    End
  78.    Begin VB.Label lblNetworkProtocol 
  79.       AutoSize        =   -1  'True
  80.       Caption         =   "#"
  81.       Height          =   195
  82.       Left            =   210
  83.       TabIndex        =   2
  84.       Top             =   3165
  85.       Width           =   2100
  86.       WordWrap        =   -1  'True
  87.    End
  88.    Begin VB.Label lblNetworkAddress 
  89.       AutoSize        =   -1  'True
  90.       Caption         =   "#"
  91.       Height          =   195
  92.       Left            =   225
  93.       TabIndex        =   0
  94.       Top             =   2535
  95.       Width           =   2100
  96.       WordWrap        =   -1  'True
  97.    End
  98.    Begin VB.Label lblRemoteServerDetails 
  99.       AutoSize        =   -1  'True
  100.       Caption         =   "#"
  101.       BeginProperty Font 
  102.          Name            =   "MS Sans Serif"
  103.          Size            =   9.75
  104.          Charset         =   0
  105.          Weight          =   400
  106.          Underline       =   0   'False
  107.          Italic          =   0   'False
  108.          Strikethrough   =   0   'False
  109.       EndProperty
  110.       Height          =   240
  111.       Left            =   360
  112.       TabIndex        =   6
  113.       Top             =   360
  114.       Width           =   7020
  115.       WordWrap        =   -1  'True
  116.    End
  117. Attribute VB_Name = "frmRemoteServerDetails"
  118. Attribute VB_GlobalNameSpace = False
  119. Attribute VB_Creatable = False
  120. Attribute VB_PredeclaredId = True
  121. Attribute VB_Exposed = False
  122. Option Explicit
  123. Option Compare Text
  124. Private m_fNetworkAddressSpecified As Boolean
  125. Private m_fNetworkProtocolSpecified As Boolean
  126. Private m_fDCOM As Boolean
  127. Private Declare Function RpcNetworkIsProtseqValid Lib "rpcrt4.dll" Alias "RpcNetworkIsProtseqValidA" (ByVal strProtseq As String) As Long
  128. ' Determines whether a given protocol sequence is supported and available on this machine
  129. Function fIsProtocolSeqSupported(ByVal strProto As String, ByVal strProtoFriendlyName) As Boolean
  130.     Const RPC_S_OK = 0&
  131.     Const RPC_S_PROTSEQ_NOT_SUPPORTED = 1703&
  132.     Const RPC_S_INVALID_RPC_PROTSEQ = 1704&
  133.     Dim rcps As Long
  134.     Static fUnexpectedErr As Boolean
  135.     On Error Resume Next
  136.     fIsProtocolSeqSupported = False
  137.     rcps = RpcNetworkIsProtseqValid(strProto)
  138.     Select Case rcps
  139.         Case RPC_S_OK
  140.             fIsProtocolSeqSupported = True
  141.         Case RPC_S_PROTSEQ_NOT_SUPPORTED
  142.             LogNote ResolveResString(resNOTEPROTOSEQNOTSUPPORTED, "|1", strProto, "|2", strProtoFriendlyName)
  143.         Case RPC_S_INVALID_RPC_PROTSEQ
  144.             LogWarning ResolveResString(resNOTEPROTOSEQINVALID, "|1", strProto, "|2", strProtoFriendlyName)
  145.         Case Else
  146.             If Not fUnexpectedErr Then
  147.                 MsgWarning ResolveResString(resPROTOSEQUNEXPECTEDERR), vbOKOnly Or vbInformation, gstrTitle
  148.                 If gfNoUserInput Then
  149.                     '
  150.                     ' This is probably redundant since this form should never
  151.                     ' be shown if we are running in silent or SMS mode.
  152.                     '
  153.                     ExitSetup frmRemoteServerDetails, gintRET_FATAL
  154.                 End If
  155.                 fUnexpectedErr = True
  156.             End If
  157.         'End Case
  158.     End Select
  159. End Function
  160. Private Sub cboNetworkProtocol_Click()
  161.     cmdOK.Enabled = fValid()
  162. End Sub
  163. Private Sub cmdCancel_Click()
  164.     ExitSetup frmRemoteServerDetails, gintRET_EXIT
  165. End Sub
  166. Private Sub cmdOK_Click()
  167.     Hide
  168. End Sub
  169. Private Sub Form_Load()
  170.     Dim fMoveControlsUp As Boolean 'Whether or not to move controls up to fill in an empty space
  171.     Dim yTopCutoff As Integer 'We will move all controls lower down than this y value
  172.     SetFormFont Me
  173.     Caption = ResolveResString(resREMOTESERVERDETAILSTITLE)
  174.     lblRemoteServerDetails.Caption = ResolveResString(resREMOTESERVERDETAILSLBL)
  175.     lblNetworkAddress.Caption = ResolveResString(resNETWORKADDRESS)
  176.     lblNetworkProtocol.Caption = ResolveResString(resNETWORKPROTOCOL)
  177.     cmdOK.Caption = ResolveResString(resOK)
  178.     cmdCancel.Caption = ResolveResString(resCANCEL)
  179.     '
  180.     ' We don't care about protocols if this is DCOM.
  181.     '
  182.     If Not m_fDCOM Then
  183.         FillInProtocols
  184.     End If
  185.     'Now we selectively turn on/off the available controls depending on how
  186.     '  much information we need from the user.
  187.     If m_fNetworkAddressSpecified Then
  188.         'The network address has already been filled in, so we can hide this
  189.         '  control and move all the other controls up
  190.         txtNetworkAddress.Visible = False
  191.         lblNetworkAddress.Visible = False
  192.         fMoveControlsUp = True
  193.         yTopCutoff = txtNetworkAddress.Top
  194.     ElseIf m_fNetworkProtocolSpecified Or m_fDCOM Then
  195.         'The network protocol has already been filled in, so we can hide this
  196.         '  control and move all the other controls up
  197.         cboNetworkProtocol.Visible = False
  198.         lblNetworkProtocol.Visible = False
  199.         fMoveControlsUp = True
  200.         yTopCutoff = cboNetworkProtocol.Top
  201.     End If
  202.     If fMoveControlsUp Then
  203.         'Find out how much to move the controls up
  204.         Dim yDiff As Integer
  205.         yDiff = cboNetworkProtocol.Top - txtNetworkAddress.Top
  206.         
  207.         Dim c As Control
  208.         For Each c In Controls
  209.             If c.Top > yTopCutoff Then
  210.                 c.Top = c.Top - yDiff
  211.             End If
  212.         Next c
  213.         
  214.         'Finally, shrink the form
  215.         Height = Height - yDiff
  216.     End If
  217.     'Center the form
  218.     Top = (Screen.Height - Height) \ 2
  219.     Left = (Screen.Width - Width) \ 2
  220. End Sub
  221. '-----------------------------------------------------------
  222. ' SUB: GetServerDetails
  223. ' Requests any missing information about a remote server from
  224. ' the user.
  225. ' Input:
  226. '   [strRegFile] - the name of the remote registration file
  227. '   [strNetworkAddress] - the network address, if known
  228. '   [strNetworkProtocol] - the network protocol, if known
  229. '   [fDCOM] - if true, this component is being accessed via
  230. '             distributed com and not Remote automation.  In
  231. '             this case, we don't need the network protocol or
  232. '             Authentication level.
  233. ' Ouput:
  234. '   [strNetworkAddress] - the network address either passed
  235. '                         in or obtained from the user
  236. '   [strNetworkProtocol] - the network protocol either passed
  237. '                          in or obtained from the user
  238. '-----------------------------------------------------------
  239. Public Sub GetServerDetails( _
  240.     ByVal strRegFile As String, _
  241.     strNetworkAddress As String, _
  242.     strNetworkProtocol As String, _
  243.     fDCOM As Boolean _
  244.     Dim i As Integer
  245.     Dim strServerName As String
  246.     'See if anything is missing
  247.     m_fNetworkAddressSpecified = (strNetworkAddress <> "")
  248.     m_fNetworkProtocolSpecified = (strNetworkProtocol <> "")
  249.     m_fDCOM = fDCOM
  250.     If m_fNetworkAddressSpecified And (m_fNetworkProtocolSpecified Or m_fDCOM) Then
  251.         'Both the network address and protocol sequence have already
  252.         'been specified in SETUP.LST.  There is no need to ask the
  253.         'user for more information.
  254.         
  255.         'However, we do need to check that the protocol sequence specified
  256.         'in SETUP.LST is actually installed and available on this machine
  257.         '(Remote Automation only).
  258.         '
  259.         If Not m_fDCOM Then
  260.             CheckSpecifiedProtocolSequence strNetworkProtocol, strGetServerName(strRegFile)
  261.         End If
  262.         
  263.         Exit Sub
  264.     End If
  265.     strServerName = strGetServerName(strRegFile)
  266.     Load Me
  267.     lblServerName.Caption = strServerName
  268.     If Not gfNoUserInput Then
  269.         '
  270.         ' Show the form and extract necessary information from the user
  271.         '
  272.         Show vbModal
  273.     Else
  274.         '
  275.         ' Since this is silent, simply accept the first one on
  276.         ' the list.
  277.         '
  278.         ' Note that we know there is at least 1 protocol in the
  279.         ' list or else the program would have aborted in
  280.         ' the Form_Load code when it called FillInProtocols().
  281.         '
  282.         cboNetworkProtocol.ListIndex = 0
  283.     End If
  284.     If m_fNetworkProtocolSpecified And Not m_fDCOM Then
  285.         'The network protocol sequence had already been specified
  286.         'in SETUP.LST.  We need to check that the protocol sequence specified
  287.         'in SETUP.LST is actually installed and available on this machine
  288.         '(32-bit only).
  289.         CheckSpecifiedProtocolSequence strNetworkProtocol, strGetServerName(strRegFile)
  290.     End If
  291.     If Not m_fNetworkAddressSpecified Then
  292.         strNetworkAddress = txtNetworkAddress
  293.     End If
  294.     If Not m_fNetworkProtocolSpecified And Not m_fDCOM Then
  295.         strNetworkProtocol = gProtocol(cboNetworkProtocol.ListIndex + 1).strName
  296.     End If
  297.     Unload Me
  298. End Sub
  299. '-----------------------------------------------------------
  300. ' SUB: FillInProtocols
  301. ' Fills in the protocol combo with the available protocols from
  302. '   setup.lst
  303. '-----------------------------------------------------------
  304. Private Sub FillInProtocols()
  305.     Dim i As Integer
  306.     Dim fSuccessReading As Boolean
  307.     cboNetworkProtocol.Clear
  308.     fSuccessReading = ReadProtocols(gstrSetupInfoFile, gstrINI_SETUP)
  309.     If Not fSuccessReading Or gcProtocols <= 0 Then
  310.         MsgError ResolveResString(resNOPROTOCOLSINSETUPLST), vbExclamation Or vbOKOnly, gstrTitle
  311.         ExitSetup frmRemoteServerDetails, gintRET_FATAL
  312.     End If
  313.     For i = 1 To gcProtocols
  314.         If fIsProtocolSeqSupported(gProtocol(i).strName, gProtocol(i).strFriendlyName) Then
  315.             cboNetworkProtocol.AddItem gProtocol(i).strFriendlyName
  316.         End If
  317.     Next i
  318.     If cboNetworkProtocol.ListCount > 0 Then
  319.         'We were successful in finding at least one protocol available on this machine
  320.         Exit Sub
  321.     End If
  322.     'None of the protocols specified in SETUP.LST are available on this machine.  We need
  323.     'to let the user know what's wrong, including which protocol(s) were expected.
  324.     MsgError ResolveResString(resNOPROTOCOLSSUPPORTED1), vbExclamation Or vbOKOnly, gstrTitle
  325.     '
  326.     ' Don't log the rest if this is SMS.  Ok for silent mode since
  327.     ' silent can take more than 255 characters.
  328.     '
  329.     If Not gfSMS Then
  330.         Dim strMsg As String
  331.         strMsg = ResolveResString(resNOPROTOCOLSSUPPORTED2) & LF$
  332.         For i = 1 To gcProtocols
  333.             strMsg = strMsg & LF$ & Chr$(9) & gProtocol(i).strFriendlyName
  334.         Next i
  335.         
  336.         MsgError strMsg, vbExclamation Or vbOKOnly, gstrTitle
  337.     End If
  338.     ExitSetup frmRemoteServerDetails, gintRET_FATAL
  339. End Sub
  340. '-----------------------------------------------------------
  341. ' SUB: strGetServerName
  342. ' Given a remote server registration file, retrieves the
  343. '   friendly name of the server
  344. '-----------------------------------------------------------
  345. Private Function strGetServerName(ByVal strRegFilename As String) As String
  346.     Const strKey = "AppDescription="
  347.     Dim strLine As String
  348.     Dim iFile As Integer
  349.     On Error GoTo DoErr
  350.     'This will have to do if we can't find the friendly name
  351.     strGetServerName = GetFileName(strRegFilename)
  352.     iFile = FreeFile
  353.     Open strRegFilename For Input Access Read Lock Read Write As #iFile
  354.     While Not EOF(iFile)
  355.         Line Input #iFile, strLine
  356.         If Left$(strLine, Len(strKey)) = strKey Then
  357.             'We've found the line with the friendly server name
  358.             Dim strName As String
  359.             strName = Mid$(strLine, Len(strKey) + 1)
  360.             If strName <> "" Then
  361.                 strGetServerName = strName
  362.             End If
  363.             Close iFile
  364.             Exit Function
  365.         End If
  366.     Wend
  367.     Close iFile
  368.     Exit Function
  369. DoErr:
  370.     strGetServerName = ""
  371. End Function
  372. Private Sub txtNetworkAddress_Change()
  373.     cmdOK.Enabled = fValid()
  374. End Sub
  375. 'Returns True iff the inputs are valid
  376. Private Function fValid() As Boolean
  377.     fValid = True
  378.     '
  379.     ' If this is dcom, we don't care about the network protocol.
  380.     '
  381.     If m_fDCOM = False Then
  382.         If Not m_fNetworkProtocolSpecified And (cboNetworkProtocol.ListIndex < 0) Then
  383.             fValid = False
  384.         End If
  385.     End If
  386.     If Not m_fNetworkAddressSpecified And (txtNetworkAddress = "") Then
  387.         fValid = False
  388.     End If
  389. End Function
  390. Private Sub CheckSpecifiedProtocolSequence(ByVal strNetworkProtocol As String, ByVal strFriendlyServerName As String)
  391.         'Attempt to find the friendly name of this protocol from the list in SETUP.LST
  392.         Dim fSuccessReading As Boolean
  393.         Dim strFriendlyName As String
  394.         Dim i As Integer
  395.         
  396.         strFriendlyName = strNetworkProtocol 'This will have to do if we can't find anything better
  397.         
  398.         fSuccessReading = ReadProtocols(gstrSetupInfoFile, gstrINI_SETUP)
  399.         If fSuccessReading And gcProtocols > 0 Then
  400.             For i = 1 To gcProtocols
  401.                 If gProtocol(i).strName = strNetworkProtocol Then
  402.                     strFriendlyName = gProtocol(i).strFriendlyName
  403.                     Exit For
  404.                 End If
  405.             Next i
  406.         End If
  407.         
  408.         'Now check to see if this protocol is available
  409.         If fIsProtocolSeqSupported(strNetworkProtocol, strFriendlyName) Then
  410.             'OK
  411.             Exit Sub
  412.         Else
  413.             'Nope, not supported.  Give an informational message about what to do, then continue with setup.
  414. Retry:
  415.             If gfNoUserInput Or MsgError( _
  416.                 ResolveResString(resSELECTEDPROTONOTSUPPORTED, "|1", strFriendlyServerName, "|2", strFriendlyName), _
  417.                 vbInformation Or vbOKCancel, _
  418.                 gstrTitle) _
  419.               = vbCancel Then
  420.                 '
  421.                 ' The user chose cancel.  Give them a chance to exit (if this isn't a silent or sms install;
  422.                 ' otherwise any call to ExitSetup is deemed fatal.
  423.                 '
  424.                 ExitSetup frmRemoteServerDetails, gintRET_EXIT
  425.                 GoTo Retry
  426.             Else
  427.                 'The user chose OK.  Continue with setup.
  428.                 Exit Sub
  429.             End If
  430.         End If
  431. End Sub
  432.